package com.smallstep.hystrix.handler;

import com.smallstep.hystrix.utils.ApplicationContextUtil;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.DefaultResponseErrorHandler;

import java.io.IOException;

/**
 * @author 李俊
 */
public class RestApiErrorHandler extends DefaultResponseErrorHandler {

    public  RestApiErrorHandler() {
    }

    @Override
    public void handleError(ClientHttpResponse response) throws IOException {
        try {
            //自定义扩展方法处理
            FFCustomErrorHandler ffCustomErrorHandler = ApplicationContextUtil
                    .getApplicationContext().getBean(FFCustomErrorHandler.class);
            ffCustomErrorHandler.handleError(response);
        } catch (NoSuchBeanDefinitionException e) {
            //默认错误扩展
            super.handleError(response);
        }

    }
}
